<template>
  <span class="at-breadcrumb__item">
    <span class="at-breadcrumb__item__inner" ref="link"><slot></slot></span><span class="at-breadcrumb__separator">{{separator}}</span>
  </span>
</template>
<script>
/**
 *@author 付雪双
 */
  export default {
    name: 'at-breadcrumb-item',
    props: {
      /**
       * @type - 连接url
       */
      to: {},
      /**
       * @type {Boolean}
       */
      replace: Boolean
    },
    data() {
      return {
        /**
         *@param {string} - 面包屑中间连接字段
         */
        separator: ''
      };
    },
    mounted() {
      /**
       *@description 如果to存在，跳转
       */
      this.separator = this.$parent.separator;
      var self = this;
      if (this.to) {
        let link = this.$refs.link;
        link.addEventListener('click', _ => {
          let to = this.to;
          self.replace ? self.$router.replace(to)
                       : self.$router.push(to);
        });
      }
    }
  };
</script>